package com.tencent.sr.iris.basic.saas.restapi.activity;

import com.tencent.sr.iris.activity.interfaces.request.IrisPaginationRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.ActivityTaskRequest;
import com.tencent.sr.iris.activity.interfaces.response.SearchAfterPaginationResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.ActivityTierResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.BatchStatisticsResponse;
import com.tencent.sr.iris.basic.saas.interfaces.request.activity.ActivityTaskPageRequest;
import com.tencent.sr.iris.basic.saas.interfaces.response.activity.ActivityTaskPageResponse;
import com.tencent.sr.iris.basic.saas.service.activity.ActivityTaskService;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@Api("活动任务详情")
@RequestMapping("/iris/basic/saas/v1/activity/task")
public class ActivityTaskController {

    @Resource
    private AppUser appUser;

    @Resource
    private ActivityTaskService activityTaskService;

    @PostMapping("page")
    @ApiOperation("任务列表")
    public HttpResult<SearchAfterPaginationResponse<ActivityTaskPageResponse>> page(
            @RequestBody @Validated IrisPaginationRequest<ActivityTaskPageRequest> request) {
        request.getQueryCriteria().setCurrentUserSaaSId(appUser.getSaasId());
        request.getQueryCriteria().setCurrentUserUid(appUser.getUid());
        SearchAfterPaginationResponse<ActivityTaskPageResponse> response = activityTaskService.page(request);
        return HttpResult.succ(response);
    }

    @ApiOperation("活动统计")
    @PostMapping("activityStatic")
    public HttpResult<BatchStatisticsResponse> activityStatic(
            @RequestBody @Validated ActivityTaskPageRequest request) {
        request.setCurrentUserSaaSId(appUser.getSaasId());
        request.setCurrentUserUid(appUser.getUid());
        BatchStatisticsResponse response = activityTaskService.activityStatic(request);
        return HttpResult.succ(response);
    }

    @ApiOperation("获取活动的最大阶数")
    @PostMapping("getActivityMaxTier")
    public HttpResult<ActivityTierResponse> getActivityMaxTier(
            @RequestBody @Validated ActivityTaskRequest request) {
        ActivityTierResponse response = activityTaskService.getActivityMaxTier(request);
        return HttpResult.succ(response);
    }
}
